package com.hs.panghu.servlet;

import com.alibaba.fastjson.JSON;
import com.hs.panghu.dao.AssociatedStoresDao;
import com.hs.panghu.dao.impl.AssociatedStoresDaoImpl;
import com.hs.panghu.entity.Shop;
import com.hs.panghu.util.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/associatedStores")
public class AssociatedStoresServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action = req.getParameter("action");
        AssociatedStoresDao associatedStoresDao=new AssociatedStoresDaoImpl();
        if ("associatedStoresList".equals(action)){
            String pageNum = req.getParameter("pageNum");
            String pageSize = req.getParameter("pageSize");
            String shopName = req.getParameter("shopName");
            String communityId = req.getParameter("communityId");
            Map<String,String>map=new HashMap<>();
            map.put("pageNum",pageNum);
            map.put("pageSize",pageSize);
            map.put("shopName",shopName);
            map.put("communityId",communityId);
            List<Shop> list = associatedStoresDao.selectAssociatedStores(map);
            int count = associatedStoresDao.selectAssociatedStoresCount(map);
            Map map1=new HashMap();
            map1.put("list",list);
            map1.put("total",count);

            Result success = Result.success(map1);

            resp.getWriter().write(JSON.toJSONString(success));


        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
